<%@page contentType="text/html;charset=UTF-8"%>
<%@ page import="whf.framework.web.Constants"%>

<%@taglib uri="/WEB-INF/tlds/struts-logic.tld" prefix="logic"%>
<%@taglib uri="/WEB-INF/tlds/struts-bean.tld" prefix="bean"%>
<%@taglib uri="/WEB-INF/tlds/struts-html.tld" prefix="html"%>
<%@taglib uri="/WEB-INF/tlds/framework.tld" prefix="framework"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title><framework:attr source="STRUTS-META" attr="name" /></title>
<jsp:include page="/common/inc/select.jsp" />
<script language="jscript" src="<%= request.getContextPath()%>/common/tree.js"></script>
<script language="jscript" src="<%= request.getContextPath()%>/scripts/xmlhttp.js"></script>
</head>

<body>
<html:form action='<%=  (String)request.getAttribute(Constants.STRUTS_PATH) %>' method="post">
<html:hidden property="webMethod" value="" />
<input name='deptIds' type='hidden'>
<framework:ext />
<framework:table pkStyle="checkbox_counter" navPosition="both" queryString="" rowExt="true" boClassName="whf.survey.entity.Survey" id="surveyList">
	<framework:caption><span class="whf_object_title"><framework:attr source="STRUTS-META" attr="name" /></span></framework:caption>
	<framework:rowext>
	<div nowrap><a href='<%= request.getContextPath() %>/survey/SurveyTopic.do?webMethod=viewTopics&view=true&_$_surveyId=${id}'>调查主题</a></div>
	</framework:rowext>
</framework:table>
<framework:funcbtn operation="prepareCreate" validationFunction="" valueKey="form.create" />
<framework:funcbtn operation="prepareUpdate" validationFunction="selectionMoreThanOne" valueKey="form.update" />
<framework:funcbtn operation="duplicate" 	validationFunction="selectionMoreThanOne" valueKey="form.duplicate" />
<framework:funcbtn operation="delete" 		validationFunction="selectionMoreThanOne" valueKey="form.delete" />
<framework:funcbtn operation="pub" 		validationFunction="selectionMoreThanOne" valueKey="form.publish" submitFunction="publish" />
<html:reset><bean:message key="form.reset" /></html:reset>

</html:form>

</body>
<script>
function publish(){
	var selectedId = getSelectedIds();
	if(selectedId.indexOf(",") >= 0) {
		alert("Only one option can be selected!");
		return;
	}
	
	var tree = new Tree();
	tree.setTreeType("framework.DeptService");
	tree.setSelectType("checkbox");
	tree.setSelectAll(false);
	tree.setRootId("<framework:attr source='whf.framework.security.UserContext' attr='user.dept.id' defaultValue='0' />");
	//tree.setQueryString("t.process is null");
	
	var checkedId = invokeServiceStringReturn("survey.SurveyPublishService", "find", "dept.id", "t.survey.id=" + selectedId)
	tree.setCheckedId(checkedId);
	
	var nodes = selectTree(tree);
	var ids = "";
	if(nodes != null){
		var arr = nodes.split(";");
		for(i=0; i< arr.length; i++){
			ids += (arr[i].split(","))[0]+","
		}
		currentForm().deptIds.value=ids;
		submitForm("pub");
	}
}
</script>
</html> 